<template>

  <el-container class="home-page">
      <!-- 头部 -->
  <el-header>
      <div>
          <img width="50" src="../assets/logo.png">
          <span>电商后台管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
  </el-header>
  <!-- 主体内容 -->
  <el-container>
      <!-- 左侧栏 -->
    <el-aside width="200px">
        <el-menu 
            unique-opened
            router
            background-color="#333744"
            text-color="#fff"
            active-text-color="dodgerblue">
            <!-- 一级菜单 -->
            <!-- <el-submenu :index="''+item.id" v-for="item in menuList" :key="item.id">
                <template slot="title">
                    <i :class="icons[item.id]"></i>
                    <span>{{item.authName}}</span>
                </template>
                二级菜单
                <el-menu-item :index="'/'+submenu.path" v-for="submenu in item.children" :key="submenu.id">
                    <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>{{submenu.authName}}</span>
                </template>
                </el-menu-item>
            </el-submenu> -->

            <el-submenu>
                <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>用户管理</span>
                </template>
                <!-- 二级菜单 -->
                <el-menu-item :index="'/users'">
                    <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>用户列表</span>
                </template>
                </el-menu-item>
            </el-submenu>
            <el-submenu>
                <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>权限管理</span>
                </template>
                <!-- 二级菜单 -->
                <el-menu-item :index="'/roles'">
                    <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>角色列表</span>
                </template>
                </el-menu-item>
                <el-menu-item :index="'/rights'">
                    <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>权限列表</span>
                </template>
                </el-menu-item>
            </el-submenu>
            <el-submenu>
                <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>商品管理</span>
                </template>
                <!-- 二级菜单 -->
                <el-menu-item :index="'/goods'">
                    <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>商品列表</span>
                </template>
                </el-menu-item>
                <el-menu-item :index="'/params'">
                    <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>分类参数</span>
                </template>
                </el-menu-item>
                <el-menu-item :index="'/categories'">
                    <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>商品分类</span>
                </template>
                </el-menu-item>
            </el-submenu>
            <el-submenu>
                <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>订单管理</span>
                </template>
                <!-- 二级菜单 -->
                <el-menu-item :index="'/orders'">
                    <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>订单列表</span>
                </template>
                </el-menu-item>
            </el-submenu>
            <el-submenu>
                <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>数据统计</span>
                </template>
                <!-- 二级菜单 -->
                <el-menu-item :index="'/reports'">
                    <template slot="title">
                    <i class="el-icon-menu"></i>
                    <span>数据报表</span>
                </template>
                </el-menu-item>
            </el-submenu>
        </el-menu>
    </el-aside>
    <!-- 右侧栏 -->
    <el-main>
        <!-- 子路由占位符 -->
        <router-view></router-view>
    </el-main>
  </el-container>
 </el-container>
</template>

<script>
export default {
    data(){
        return {
            menuList:[],
            icons:{
                '125':'iconfont icon-user',
                '103':'iconfont icon-3702mima',
                '101':'iconfont icon-shangpin',
                '102':'iconfont icon-danju',
                '145':'iconfont icon-baobiao',

            }
        }
    }
    ,
    created(){
        //获取左侧栏数据
        this.getMenuList();
    }
    ,
    methods:{
        //退出
        logout(){
            sessionStorage.clear();
            this.$router.push('/login');
            this.$message.success('退出成功');
        },
        async getMenuList(){
            //解构
            let {data:ret}=await this.$http.get('menus');
            console.log(ret);
            //容错
            if(ret.meta.status!=200){
                return this.$message.error(ret.meta.msg);
            }
            this.menuList=ret.data;
        }
    }
}
</script>

<style lang="less" scoped>
    .el-header{
        background-color: #373d41;
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #fff;
        font-size: 20px;
        div{
            display: flex;
            align-items: center;
        }
    }
    .el-aside{
        background-color: #333744;
        .el-menu{
            border-right: none;
        }
    }
    .el-main{
        background-color: #eaedfe;
    }
    .home-page{
        height: 100%;
    }
.iconfont{
    margin-right: 10px;
}
</style>